import React from "react";
import { Children } from './Children'
// 导入样式
import './parent.css'
export class Parent extends React.Component {
  state = {
    list: [
      {
        id: 1,
        name: '超级好吃的棒棒糖',
        price: 18.8,
        info: '开业大酬宾，全场8折',
      },
      {
        id: 2,
        name: '超级好吃的大鸡腿',
        price: 34.2,
        info: '开业大酬宾，全场8折',
      },
      {
        id: 3,
        name: '超级无敌的冰激凌',
        price: 14.2,
        info: '开业大酬宾，全场8折',
      },
    ],
  }
  kan = (id, prices) => {
    const newList = this.state.list.map(item => {
      if (item.id === id) {
        return {
          ...item,
          price: item.price - prices
        }
      } else {
        return item
      }
    })
    this.setState({
      list: newList
    })
  }
  render() {
    return (
      <div className="parent">
        <h1>父组件</h1>
        {/* 把下面UI抽离为子组件 */}
        {
          this.state.list.map(item => (
            <Children key={item.id} kans={this.kan} list={item}></Children>
          ))
        }
      </div>
    )
  }
}

